import type { RecipeType } from '../model/recipe'
import http from '../utils/http'
//获取全部菜谱
export const getRecipe=():Promise<RecipeType[]>=>{
	return http.get('/classes/Recipe',{
		params:{
			limit:4,
			skip:Math.floor(Math.random()*10+5)
		}
	}).then(res => res.data.results) 
}
//获取低卡菜谱
export const getLowCarories=():Promise<RecipeType[]>=>{
	return http.get('/classes/Recipe',{
		params:{
			where:{ calories: { $regex: '^[0-2]\\d{2}大卡|^300大卡' } //低于300大卡
			},
			limit:4,
		}
	}).then(res => res.data.results) 
}
//获取某一个菜谱
export const getDetailRecipe=(id:string)=>{
	return http.get(`/classes/Recipe/${id}`)
}
//搜索菜谱
export const searchRecipe=(keyword:string):Promise<RecipeType[]>=>{
	return http.get('/classes/Recipe',{
		params:{
			where:{
				name: { $regex: keyword } // 使用正则表达式实现模糊搜索
			},
			limit:5
		},
	}).then(res => res.data.results) 
}